/**
* 基础菜单 空间管理
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>空间管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.address" placeholder="输入地址"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-collapse v-model="activeName" accordion @change="activeChanged">
    
    </el-collapse>
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
  import {
    SpaceList,
    SpaceDevices
  } from '../../api/spaceApi'
  import Pagination from '../../components/Pagination'
  export default {
    data() {
      return {
        loading: false, //是显示加载
        editFormVisible: false,
        title: '添加',
        formInline: {
          page: 1,
          limit: 10,
          address: ''
        },
        editForm: {
          id: '',
          name: ''
        },
        // 分页参数
        pageparm: {
          currentPage: 1,
          pageSize: 10,
          total: 10
        },
        userparm: [], //搜索权限
        listData: [], //用户数据
        activeName: "",
        allSpaceDevices: {},
        spaceDevices: [{
          name: "卧室门锁1",
          info: {
            state: {}
          }
        }]
      }
    },
    // 注册组件
    components: {
      Pagination
    },
    /**
     * 数据发生改变
     */

    /**
     * 创建完毕
     */
    created() {
      this.getdata(this.formInline)
    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {
      getdata(parameter) {
        this.loading = true
        SpaceList(parameter)
          .then(res => {
            this.loading = false

            this.listData = res.data
            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.count

          }, () => {
            this.loading = false
          })
      },
      // 搜索事件
      search() {
        this.getdata(this.formInline)
      },
      activeChanged(name) {
        if (!name) {
          return;
        }
        let devices = this.allSpaceDevices[name];
        if (devices && devices.length > 0) {
          this.spaceDevices = devices
          return
        }

        this.loading = true
        SpaceDevices(name)
          .then(res => {
            this.loading = false
            this.spaceDevices = res
            this.allSpaceDevices[name] = res
          }, () => {
            this.loading = false
          })
      },
      // 分页插件事件
      callFather(parm) {
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.getdata(this.formInline)
      },
      handleEdit: function(index, row) {
        this.editFormVisible = true
        if (row != undefined && row != 'undefined') {
          this.title = '编辑品类'
          this.editForm.id = row.id
          this.editForm.name = row.name
        } else {
          this.title = '添加品类'
          this.editForm.id = ''
          this.editForm.name = ''
        }
      },
      submitEditForm() {

      },
      // 关闭编辑、增加弹出框
      closeDialog() {
        this.editFormVisible = false
      }
    }
  }
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }

  .userRole {
    width: 100%;
  }

  .image {
    width: 100%;
    display: block;
  }

  .box-card .item {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }

  .mac {
    font-size: 13px;
    color: #666666;
  }
</style>
